Skip to content

pdo: handle none cob_id correctly in __repr__#640

Open
stoicfeats wants to merge 1 commit intocanopen-python:masterfrom
stoicfeats:fix-pdo-repr-crash
Open

pdo: handle none cob_id correctly in __repr__#640
stoicfeats wants to merge 1 commit intocanopen-python:masterfrom
stoicfeats:fix-pdo-repr-crash

Conversation

@stoicfeats
Copy link
Copy Markdown

@stoicfeats stoicfeats commented Apr 16, 2026

fxes a crash when calling repr() on a pdomap that doesn't have a cob_id assigned yet.

before this, working in an interactive session would throw a typeerror if we evaluated uninitialized maps like node.rpdo[1].
the string formatter was trying to apply : X hex-formatting to a nonetype value.

this adds a quick inline fallback so it prints "unassigned" instead of throwing error on the console.

@stoicfeats
Copy link
Copy Markdown
Author

@acolomb please have a look into this, thanks.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
canopen/pdo/base.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@acolomb
Copy link
Copy Markdown
Member

acolomb commented Apr 16, 2026

Hi and thanks for your contribution. I've experienced the issue you mention several times. It's usually a sign of weird ordering in the API usage, because you need to assign a valid COB ID by some means first. But sure, the __repr__ case is very easy to hit without even trying any actual bus configuration.

We have several more places that can fail with the same error, mainly logging calls but also send_message() and friends. Ideally, we would forbid the cob_id member to ever be None (rather zero, which is also not valid). But that's a rather large change.

Would you mind checking the other places though, to fix other occurrences where the format strings can easily explode with cob_id = None?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants